package com.neu.icloud.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.neu.icloud.entity.Mechine;

@Mapper
public interface MechineMapper {
	
	@Insert("insert into mechine values(#{mechineId},#{mechineName},#{mechineState},#{mechineImg},#{mechineCop},#{factoryId})")
	public int addMechine(Mechine mechine);
	
	@Update("update mechine set mechineImg = #{mechineImg},mechineCop = #{mechineCop},factoryId = #{factoryId} where mechineId = #{mechineId}")
	public int updataMechine(Mechine mechine);
	
	@Update("update mechine set mechineState = #{mechineState} where mechineId = #{mechineId}")
	public int updateMechineState(Mechine mechine);
	
	//通过设备ID删除
	@Delete("delete from mechine where mechineId = #{mechineId}")
	public int removeMechineByMechineId(String mechineId);
	
	//通过工厂ID删除
	@Delete("delete from mechine where factoryId = #{factoryId}")
	public int removeMechineByFactoryId(Integer factoryId);
	
	//通过设备ID查询
	@Select("select * from mechine where mechineId = #{mechineId}")
	public List<Mechine> listMechineByMechineId(String mechineId);
	
	//通过工厂ID查询
	@Select("select * from mechine where factoryId = #{factoryId}")
	public List<Mechine> listMechineByFactoryId(Integer factoryId);
	
	@Select("select * from mechine")
	public List<Mechine> selectAll();
	
	@Select("select count(*) from mechine where mechineState = #{mechineState}")
	public int runNum(String mechineState);
	
	@Select("select count(*) from mechine order by mechineId")
	public int allNum();
}
